<!--
 * @Date         : 2020-10-28 09:42:58
 * @LastEditors  : zhangyu
 * @LastEditTime : 2020-11-04 15:46:39
 * @Description  : 
-->
<template>
  <div class="table-box">
    <div class="page-header">菜单管理</div>
	<el-button type="primary" @click="handleAdd" class="addBtn">新增菜单</el-button>
    <el-table :data="menus" style="width: 100%">
      <el-table-column prop="sort" label="排序" width="180"> </el-table-column>
      <el-table-column prop="title" label="菜单名称"> </el-table-column>
      <el-table-column prop="parent" label="上级菜单"> </el-table-column>
      <el-table-column prop="url" label="跳转路由"> </el-table-column>
      <el-table-column prop="node" label="权限节点"> </el-table-column>
      <el-table-column prop="create_time" label="创建时间"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      menus: [],
    };
  },
  async created() {
    let res = await this.$http.get("menu/list");
    this.menus = res;
  },
  methods: {
    handleEdit(idx, row) {
      this.$router.push("/menu/edit/" + row.id);
    },
	handleAdd(){
		this.$router.push('/menu/add')
	},
    async handleDelete(idx, row) {
      await this.$confirm(
        `此操作将永久删除菜单「${row.title}」, 是否继续?`,
        "提示",
        { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }
      );
      await this.$http.post('/menu/remove',{id:row.id})
      this.$message.success('删除成功')
      let res = await this.$http.get("menu/list");
      this.menus = res;
    },
  },
};
</script>

<style scoped>
  
</style>

